package com.atguigu.gmall.common.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
import com.baomidou.mybatisplus.core.injector.SqlRunnerInjector;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * MybatisPlus配置类
 *
 * @author fxz
 */
@EnableTransactionManagement
@Configuration
@MapperScan("com.atguigu.gmall.*.mapper")
public class MybatisPlusConfig {

	/**
	 * 最新版 分页插件
	 */
	@Bean
	public MybatisPlusInterceptor mybatisPlusInterceptor() {
		MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
		interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
		return interceptor;
	}

	/**
	 * 自定义 SqlInjector 里面包含自定义的全局方法
	 */
	@Bean
	public DefaultSqlInjector myLogicSqlInjector() {
		SqlRunnerInjector sqlRunnerInjector = new SqlRunnerInjector();
		return new DefaultSqlInjector();
	}

	/**
	 * SQL执行效率插件
	 */

	/*
	 * @Bean
	 *
	 * @Profile({"dev", "test"}) // 设置 dev test 环境开启 public PerformanceInterceptor
	 * performanceInterceptor() { PerformanceInterceptor performanceInterceptor = new
	 * PerformanceInterceptor(); performanceInterceptor.setMaxTime(2000);
	 * performanceInterceptor.setFormat(true); return performanceInterceptor; }
	 */

}
